<?php
/**
 * 前台控制器
 * 
 * @author  : $Author: spike $
 * @date    : $Date: 2014-03-26 15:45:00 +0800 (三, 2014-03-26) $
 * @version : $Id: MY_Controller.php 72 2014-03-26 07:45:00Z spike $
 * @rev     : $Revision: 72 $
 */
class MY_Controller extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        // 预先存入的全局数据
        $data = array(
            '_recommended_goods' => $this->config->item('recommended_goods'),
            '_menu'              => $this->_get_menu(),
        );

        $this->load->vars($data);
    }


    /**
     * [获取系统菜单]
     * @return
     */
    public function _get_menu()
    {
        if( ! isset($_SESSION['_menu!']) )
        {    
            // 获取category
            $this->load->dao('Category_dao');
            $category = $this->Category_dao->get(
                array('status'=>CATEGORY_STATUS_ON, 'is_delete'=>UNDELETED),
                array('name', 'seo_name'),
                '`sort` ASC'
            );

            $c_menu = array();
            foreach ($category as $c) 
            {
                $c_menu[$c['name']] = DOMAIN."goods/search/?cat={$c['seo_name']}";
            }

            // 获取attr
            $this->load->dao('Attr_value_dao');
            $attr_value = $this->Attr_value_dao->get(
                array('status'=>ATTR_VALUE_STATUS_ON, 'is_delete'=>UNDELETED, 'attr_id'=>25),
                array('name', 'attr_id','attr_value_id'),
                '`sort` ASC'
            );

            $a_menu = array();
            foreach ($attr_value as $a) 
            {
                $a_menu[$a['name']] = DOMAIN."goods/attr/?attr={$a['attr_id']}-{$a['attr_value_id']}";
            }

            $_SESSION['_menu'] = array(
                array(
                    'name'     => '新品速度',
                    'url'      => DOMAIN.'goods/new_release',
                    'children' => array(),
                ),
                array(
                    'name'     => '热销宝贝',
                    'url'      => DOMAIN.'goods/most_popular',
                    'children' => array(),
                ),
                array(
                    'name'     => '宝贝详情',
                    'url'      => '',
                    'children' => & $c_menu,
                ),
                array(
                    'name'     => 'TCFS家族',
                    'url'      => '',
                    'children' => & $a_menu,
                ),
                array(
                    'name'     => '市场动态',
                    'url'      => DOMAIN.'trend/search',
                    'children' => array(),
                ),
                array(
                    'name'     => '美妆课堂',
                    'url'      => DOMAIN.'beauty',
                    'children' => array(),
                ),
                array(
                    'name'     => '酷粉家园',
                    'url'      => DOMAIN.'coolpowder',
                    'children' => array(),
                ),
                array(
                    'name'     => '关于TCFS',
                    'url'      => '',
                    'children' => array(
                        'Too Cool精神' => DOMAIN.'about_us/spirit',
                        '我们的故事'   => DOMAIN.'about_us/story',
                        '店铺介绍'     => DOMAIN.'about_us/contact_us',
                    ),
                ),
            );
        }

        return $_SESSION['_menu'];
    }
}